home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 15.0 KB | 484 lines | [TEXT/MPS ] |
- // UAppleEvents.h
- // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
-
- #ifndef __UAPPLEEVENTS__
- #define __UAPPLEEVENTS__
-
- // MacApp
-
- #ifndef __GEOMETRY__
- #include "Geometry.h"
- #endif
-
- #ifndef __TOOLBOX__
- #include "Toolbox.h"
- #endif
-
- #ifndef __UFAILURE__
- #include "UFailure.h"
- #endif
-
- #ifndef __UOBJECT__
- #include "UObject.h"
- #endif
-
- // Toolbox
-
- #ifndef __APPLEEVENTS__
- #include <AppleEvents.h>
- #endif
-
- #ifndef __EDITIONS__
- #include <Editions.h>
- #endif
-
- //----------------------------------------------------------------------------------------
- // Mask constants for testing sending mode.
- //----------------------------------------------------------------------------------------
-
- const long kAEReplyModeMask = 0x0000000F; // Mask for reply mode
- const long kAEInteractModeMask = 0x00000030; // Mask for interact mode
-
- //----------------------------------------------------------------------------------------
- // Forward and external class declarations.
- //----------------------------------------------------------------------------------------
-
- class TDynamicArray;
- class TFile;
- class MScriptableObject;
- class CAEDesc;
-
- //----------------------------------------------------------------------------------------
- // CAEDesc : Wraps around a AEDesc and provides lots of extra services. Use this
- // instead of an AEDesc and you'll have access to those services.
- //----------------------------------------------------------------------------------------
-
- class CAEDesc
- {
- public:
- CAEDesc();
- CAEDesc(const AEDesc& theDesc);
- CAEDesc(const AEDesc* theDesc);
- CAEDesc(DescType theType,
- Handle theHandle);
-
- // Wrappers for toolbox functions
-
- Boolean CanCoerceDesc(DescType toType) const;
- void CoerceDesc(DescType toType, AEDesc *result) const;
- void CreateDesc(DescType typeCode, const void *dataPtr, Size dataSize);
- OSErr DisposeDesc();
- OSErr GetKeyPtr(AEKeyword theAEKeyword, DescType desiredType, DescType *typeCode,
- void *dataPtr, Size maximumSize, Size *actualSize) const;
- void PutKeyPtr(AEKeyword theAEKeyword, DescType typeCode,
- const void *dataPtr, Size dataSize);
-
- // Conversion operator methods
-
- inline operator AEDesc() { return fAEDesc; }
- inline operator const AEDesc() const { return fAEDesc; }
-
- inline operator AEDesc&() { return fAEDesc; }
- inline operator const AEDesc&() const { return fAEDesc; }
-
- inline operator AEDesc*() { return &fAEDesc; }
- inline operator const AEDesc*() const { return &fAEDesc; }
-
- CAEDesc& operator=(const CAEDesc& theDesc);
-
- // Desc content comparison method
-
- Boolean EqualDesc(const CAEDesc& theDesc) const;
-
- Boolean CompareDesc(const CAEDesc& theDesc, DescType compareHow) const;
-
- // Methods to get and set data on the fAEDesc.
-
- void SetDesc(DescType theType,
- Handle theHandle);
- inline DescType GetDescriptorType() const { return fAEDesc.descriptorType; }
-
- inline Handle GetDataHandle() const { return fAEDesc.dataHandle; }
-
- long GetDataSize() const;
-
- // The following methods treat the CAEDesc as a list of descriptors
-
- void CreateList();
- // Creates an AEList with no factoring information
-
- long CountListItems();
- // Returns the number of items in the list
-
- void GetNthItem(long index, DescType desiredType, CAEDesc& theDesc);
- // Gets the Nth AEDesc from the list
-
- void PutListItem(long index, CAEDesc& theDesc);
- // Puts theDesc into the list at the index position.
-
- OSErr DeleteListItem(long index);
- // Puts theDesc at the index position from the list.
-
- // The following methods are for storing and retrieving various data
- // types from CAEDescs
-
- void GetFSSpec(FSSpec& fileSpec) const;
- void PutFSSpec(const FSSpec& fileSpec);
-
- void GetRect(CRect& theRect) const;
- void PutRect(const CRect& theRect);
-
- DescType GetType() const;
- void PutType(DescType theType);
-
- void PutString(const CStr255& theString);
- void GetString(CStr255& theString,
- long maximumSize = 255) const;
-
- void PutBoolean(Boolean theBoolean);
- Boolean GetBoolean() const;
-
- void PutEnum(DescType theEnum);
- DescType GetEnum() const;
-
- void PutLong(long theLong);
- long GetLong() const;
-
- void PutDateTime(unsigned long theDateTime);
- unsigned long GetDateTime() const;
-
- void GetRGBColor(CRGBColor& theColor) const;
- void PutRGBColor(const CRGBColor& theColor);
-
- MScriptableObject* GetObject() const;
- void PutObject(MScriptableObject* theObject);
-
- // Methods for dealing with records
-
- void CreateRecord();
-
- // The following GetKeyXXX and PutKeyXXX methods are for easy access to AERecords
- // The GetKeyXXX methods will not fail but will return FALSE if the key did not exist.
- // This is so you can use them to attempt to retrieve optional keys in a record without
- // handling failure or checking first to see if they exist.
-
- Boolean GetKeyLong(DescType theKey,
- long& theNum) const;
- void PutKeyLong(DescType theKey,
- long theNum);
-
- Boolean GetKeyRect(DescType theKey,
- CRect& theRect) const;
- void PutKeyRect(DescType theKey,
- const CRect& theRect);
-
- Boolean GetKeyString(DescType theKey,
- CStr255& theStr,
- long maximumSize = 255) const;
- void PutKeyString(DescType theKey,
- const CStr255& theStr);
-
- Boolean GetKeyDateTime(DescType theKey,
- unsigned long& theDate) const;
- void PutKeyDateTime(DescType theKey,
- unsigned long theDate);
-
- Boolean GetKeyBoolean(DescType theKey,
- Boolean& theBoolean) const;
- void PutKeyBoolean(DescType theKey,
- Boolean theBoolean);
-
- Boolean GetKeyColor(DescType theKey,
- CRGBColor& theColor) const;
- void PutKeyColor(DescType theKey,
- const CRGBColor& theColor);
-
- Boolean GetKeyEnum(DescType theKey,
- DescType& theEnum) const;
- void PutKeyEnum(DescType theKey,
- DescType theEnum);
-
- Boolean GetKeyDesc(DescType theKey,
- DescType desiredType,
- CAEDesc& theAEDesc) const;
-
- void PutKeyDesc(DescType theKey,
- CAEDesc& theAEDesc);
-
- OSErr DeleteKeyDesc(DescType theKey);
-
- // Stream I/O methods
-
- void ReadFrom(TStream* aStream);
- void WriteTo(TStream* aStream);
-
- // Resource I/O methods
-
- void ReadFrom(TFile* aFile, ResType resourceType, short resourceID);
- void WriteTo(TFile* aFile, short resourceID, CStr255& resourceName);
-
- //----------------------------------------------------------------------------------------
- // data members
- //----------------------------------------------------------------------------------------
- public:
- AEDesc fAEDesc; // the AEDesc record
-
- //----------------------------------------------------------------------------------------
- // static data members
- //----------------------------------------------------------------------------------------
- public:
- static CAEDesc fgNullDesc;
- };
-
- //----------------------------------------------------------------------------------------
- // CTempDesc
- //----------------------------------------------------------------------------------------
-
- class CTempDesc : public CAEDesc
- {
- // This varient of CAEDesc is designed for the occasions when you need to create
- // a descriptor that you will only use within a limited scope. CTempDesc destructor
- // will call AEDisposeDesc for you to simplify cleanup.
-
- public:
- CTempDesc();
- CTempDesc(const AEDesc& theDesc);
- CTempDesc(DescType theType,
- Handle theHandle);
- // Initializes the fAEDesc and installs the failure handler.
- ~CTempDesc();
- // Calls Success for the failure handler.
-
- void Cleanup();
-
- //----------------------------------------------------------------------------------------
- // static member functions
- //----------------------------------------------------------------------------------------
- public:
- static void CallCleanup(void* context);
-
- //----------------------------------------------------------------------------------------
- // data members
- //----------------------------------------------------------------------------------------
- private:
- FailInfo fFailInfo; // the failure record that references
-
- };
-
- //----------------------------------------------------------------------------------------
- // TAppleEvent
- //----------------------------------------------------------------------------------------
-
- class TAppleEvent : public TObject
- {
- MA_DECLARE_CLASS;
-
- public:
- TAppleEvent();
- // Constructor
-
- void IAppleEvent(const AEEventClass itsEventClass,
- const AEEventID itsEventID,
- const AEAddressDesc& itsAddress,
- long itsSendingMode);
-
-
- // Creates a new AppleEvent message and stores it in fMessage. Supplies
- // defaults for return ID, transaction ID, and sending priority.
-
- virtual void InitializeFromMessage(const AppleEvent& theMessage,
- Boolean freeMessage);
- // Stores theMessage in fMessage. This may be a message or a reply. If freeMessage is true
- // Free the message when freeing the object
-
- virtual ~TAppleEvent();
-
- virtual OSErr SendEvent();
- // Send the apple event. Will not throw an exception. Preferred method.
-
- virtual OSErr SendEvent(TAppleEvent*& replyEvent);
- // Send the apple event and get a reply event. Will not throw an exception. Preferred Method.
-
- virtual TAppleEvent* Send();
- // Send the apple event and return a reply. WILL throw an exception if an error occurs.
- // Present for compatibility - use SendEvent when possible.
-
- virtual void GetAddress(AEAddressDesc& theAddress);
- // Return the target address of the message
-
- void GetProcessSerialNumber(ProcessSerialNumber& thePSN);
- // Return the Process Serial Number for the sender of the message
-
- inline short GetPriority()
- { return fPriority; }
- // Return the sending priority of the message
-
- virtual long GetReturnID();
- // Return the ID assigned to the message
-
- inline long GetSendingMode()
- { return fSendingMode; }
- // Return the sending mode of the event
-
- inline long GetTimeoutVal()
- { return fTimeoutVal; }
- // Return the timeout value (in ticks) used when sending the message
-
- virtual long GetTransactionID();
- // Return the ID of the transaction the message belongs to
-
- virtual void SetAddress(const AEAddressDesc& theAddress);
- // Assign the target address of the message
-
- virtual void SetPriority(short thePriority);
- // Assign the priority with which the message will be sent
-
- virtual void SetReturnID(long returnID);
- // Assign a new return ID to the message
-
- virtual void SetSendingMode(long sendingMode);
- // Specify a new way of sending the message
-
- virtual void SetTimeoutVal(long theTimeoutVal);
- // Assign the time (in ticks) to wait for reply if sending kAEWaitReply
-
- virtual void SetTransactionID(long transactionID);
- // Assign a transaction ID to the message
-
- AEEventClass ReadEventClass();
- // Return the event class of the apple event
-
- AEEventID ReadEventID();
- // Return the event ID
-
- // READING - The following methods retrieve theData from fMessage based on the keyword
- virtual short ReadShort(const AEKeyword theKey);
-
- virtual long ReadLong(const AEKeyword theKey);
-
- virtual void ReadString(const AEKeyword theKey,
- CStr255& theData);
-
- virtual SectionHandle ReadSectionHandle(const AEKeyword theKey);
-
- virtual void ReadPtrList(const AEKeyword theKey,
- const DescType theType,
- TDynamicArray* theData);
-
- virtual void ReadHandleList(const AEKeyword theKey,
- const DescType theType,
- TDynamicArray* theData);
-
- virtual DescType ReadType(const AEKeyword theKey);
-
- virtual DescType ReadEnum(const AEKeyword theKey);
-
- virtual Boolean ReadBoolean(const AEKeyword theKey);
-
- virtual void ReadRect(const AEKeyword theKey,
- CRect& theRect);
-
- virtual void ReadError(long& errorNumber, CStr255& errorString);
-
- // Allow raw read access to a parameter of the message
-
- virtual OSErr ReadParameter(const AEKeyword theKey,
- const DescType desiredType,
- CAEDesc& theData);
-
-
- virtual void ReadParameterPtr(const AEKeyword theKey,
- const DescType desiredType,
- DescType& actualType,
- Ptr theData,
- long maximumSize,
- long& actualSize);
-
- // WRITING - The following methods store theData in fMessage with theKey
- virtual void WriteShort(const AEKeyword theKey,
- short theData);
-
- virtual void WriteLong(const AEKeyword theKey,
- long theData);
-
- virtual void WriteString(const AEKeyword theKey,
- const CStr255& theData);
-
- virtual void WriteSectionHandle(const AEKeyword theKey,
- SectionHandle theData);
-
- virtual void WritePtrList(const AEKeyword theKey,
- const DescType theType,
- TDynamicArray* theData);
-
- virtual void WriteHandleList(const AEKeyword theKey,
- const DescType theType,
- TDynamicArray* theData);
-
- virtual void WriteEnum(const AEKeyword theKey,
- DescType theEnum);
-
- virtual void WriteType(const AEKeyword theKey,
- DescType theType);
-
- virtual void WriteBoolean(const AEKeyword theKey,
- Boolean theBoolean);
-
- virtual void WriteRect(const AEKeyword theKey,
- const CRect& theRect);
-
- // Allow raw access to a parameter of the message
-
- virtual void WriteParameter(const AEKeyword theKey,
- const CAEDesc& theData);
-
- virtual void WriteParameterPtr(const AEKeyword theKey,
- const DescType typeCode,
- Ptr theData,
- long dataSize);
-
- virtual void DeleteParameter(const AEKeyword theKey);
- // Delete the specified parameter from the message
-
- virtual void CheckRequiredParameters();
-
- virtual Boolean HasParameter(const AEKeyword theKey);
-
- virtual DescType ParameterType(const AEKeyword theKey);
-
- virtual Boolean WriteReplySpecifier(MScriptableObject* theReplyObject);
- // Use this whenever you need to return the object's specifier as the result of an event.
- // Makes an object specifier for an object and puts it in the keyAEResult parameter of this event.
-
- void WriteError(long errNum, short errorStringResource, short errorStringIndex);
- void WriteOSError(OSErr error);
- // Report an error back to the client using the errReasonID 'errs' resource.
-
- //----------------------------------------------------------------------------------------
- // static functions
- //----------------------------------------------------------------------------------------
- public:
- static TAppleEvent* MakeCreateElementEvent(AEAddressDesc& targetAddress, AESendMode sendMode,
- CAEDesc& targetSpecifier, DescType newElementType, DescType newElementPosition,
- CAEDesc& initialData, CAEDesc& initialProperties);
-
- //----------------------------------------------------------------------------------------
- // data members
- //----------------------------------------------------------------------------------------
- public:
- AppleEvent fMessage; // Created by IAppleEvent, Set from InitializeFromMessage
- long fSendingMode; // kAENoReply, kAEQueueReply, or kAEWaitReply
- long fTimeoutVal; // How long should we wait for a response?
- short fPriority; // kAENormalPriority or kAEHighPriority
- Boolean fFreeMessage; // If true then free the message when freeing the object
-
- //----------------------------------------------------------------------------------------
- // static data members
- //----------------------------------------------------------------------------------------
- public:
- static AEIdleUPP fgIdleProc;
- static AEFilterUPP fgFilterProc;
- };
-
- #endif
-